<form #form [formGroup]="formGroup" (ngSubmit)="submit()" [appApiAction]="formPromise">
  <div class="content">
    <div class="inner-content" *ngIf="send">
      <div class="box">
        <app-callout *ngIf="disableSend">
          <span>{{ "sendDisabledWarning" | i18n }}</span>
        </app-callout>
        <app-callout type="info" *ngIf="disableHideEmail && !disableSend">
          {{ "sendOptionsPolicyInEffect" | i18n }}
        </app-callout>
      </div>
      <div class="box">
        <h2 class="box-header">
          {{ title }}
        </h2>
        <div class="box-content">
          <div class="box-content-row" appBoxRow>
            <label for="name">{{ "name" | i18n }}</label>
            <input id="name" type="text" name="Name" formControlName="name" appAutofocus />
          </div>
          <div class="box-content-row box-content-row-radio" *ngIf="!editMode">
            <label class="radio-header">{{ "whatTypeOfSend" | i18n }}</label>
            <div class="item" *ngFor="let o of typeOptions">
              <input
                type="radio"
                class="radio"
                formControlName="type"
                id="type_{{ o.value }}"
                [value]="o.value"
              />
              <label class="unstyled" for="type_{{ o.value }}">
                {{ o.name }}
              </label>
            </div>
          </div>
          <div class="box-content-row" appBoxRow *ngIf="!editMode && type === sendType.File">
            <label for="file">{{ "file" | i18n }}</label>
            <input
              type="file"
              id="file"
              class="form-control-file"
              name="file"
              aria-describedby="fileHelp"
              required
            />
          </div>
          <div class="box-content-row" appBoxRow *ngIf="editMode && type === sendType.File">
            <label for="file">{{ "file" | i18n }}</label>
            <div class="row-main">{{ send.file.fileName }} ({{ send.file.sizeName }})</div>
          </div>
          <div class="box-content-row" appBoxRow *ngIf="type === sendType.Text">
            <label for="text">{{ "text" | i18n }}</label>
            <textarea
              id="text"
              name="text"
              aria-describedby="textHelp"
              formControlName="text"
              rows="6"
            ></textarea>
          </div>
        </div>
        <div id="fileHelp" class="box-footer" *ngIf="!editMode && send.type === sendType.File">
          {{ "sendFileDesc" | i18n }} {{ "maxFileSize" | i18n }}
        </div>
        <div id="textHelp" class="box-footer" *ngIf="send.type === sendType.Text">
          {{ "sendTextDesc" | i18n }}
        </div>
      </div>
      <div class="box" *ngIf="send.type === sendType.Text">
        <div class="box-content">
          <div class="box-content-row box-content-row-checkbox" appBoxRow>
            <label for="hideText">{{ "textHiddenByDefault" | i18n }}</label>
            <input id="hideText" name="hideText" type="checkbox" formControlName="textHidden" />
          </div>
        </div>
      </div>
      <div class="box">
        <h2 class="box-header">
          <button
            type="button"
            class="toggle"
            appStopClick
            (click)="toggleOptions()"
            [attr.aria-expanded]="showOptions"
          >
            <i
              class="bwi bwi-lg"
              aria-hidden="true"
              [ngClass]="{ 'bwi-angle-right': !showOptions, 'bwi-angle-down': showOptions }"
            ></i>
            {{ "options" | i18n }}
          </button>
        </h2>
      </div>
      <div [hidden]="!showOptions">
        <div class="box">
          <div class="box-content">
            <div class="box-content-row" appBoxRow *ngIf="!editMode">
              <label for="deletionDate">{{ "deletionDate" | i18n }}</label>
              <select
                id="deletionDate"
                name="DeletionDateSelect"
                aria-describedby="deletionDateHelp"
                formControlName="selectedDeletionDatePreset"
                required
              >
                <option *ngFor="let o of deletionDatePresets" [ngValue]="o.value">
                  {{ o.name }}
                </option>
              </select>
              <small id="deletionDateHelp" class="help-block">{{
                "deletionDateDesc" | i18n
              }}</small>
            </div>
            <div
              class="box-content-row"
              *ngIf="formGroup.controls['selectedDeletionDatePreset'].value === 0 || editMode"
            >
              <label *ngIf="editMode" for="deletionDateCustom">{{ "deletionDate" | i18n }}</label>
              <input
                id="deletionDateCustom"
                type="datetime-local"
                name="deletionDate"
                aria-describedby="deletionDateCustomHelp"
                formControlName="defaultDeletionDateTime"
                required
                placeholder="MM/DD/YYYY HH:MM AM/PM"
              />
              <small id="deletionDateCustomHelp" class="help-block" *ngIf="editMode">{{
                "deletionDateDesc" | i18n
              }}</small>
            </div>
            <div class="box-content-row" appBoxRow *ngIf="!editMode">
              <label for="expirationDate">{{ "expirationDate" | i18n }}</label>
              <select
                id="expirationDate"
                name="expirationDateSelect"
                aria-describedby="expirationDateHelp"
                formControlName="selectedExpirationDatePreset"
                required
              >
                <option *ngFor="let o of expirationDatePresets" [ngValue]="o.value">
                  {{ o.name }}
                </option>
              </select>
              <small id="expirationDateHelp" class="help-block">{{
                "expirationDateDesc" | i18n
              }}</small>
            </div>
            <div
              class="box-content-row"
              *ngIf="formGroup.controls['selectedExpirationDatePreset'].value === 0 || editMode"
            >
              <label *ngIf="editMode" for="expirationDateCustom">{{
                "expirationDate" | i18n
              }}</label>
              <input
                id="expirationDateCustom"
                type="datetime-local"
                name="expirationDate"
                aria-describedby="expirationDateCustomHelp"
                formControlName="defaultExpirationDateTime"
                required
                placeholder="MM/DD/YYYY HH:MM AM/PM"
              />
              <small *ngIf="editMode" id="expirationDateCustomHelp" class="help-block">{{
                "expirationDateDesc" | i18n
              }}</small>
            </div>
          </div>
        </div>
        <div class="box">
          <div class="box-content">
            <div class="box-content-row" appBoxRow>
              <label for="maxAccessCount">{{ "maxAccessCount" | i18n }}</label>
              <input
                id="maxAccessCount"
                type="number"
                name="maxAccessCount"
                aria-describedby="maxAccessCountHelp"
                formControlName="maxAccessCount"
              />
            </div>
          </div>
          <div id="maxAccessCountHelp" class="box-footer" *ngIf="!editMode">
            {{ "maxAccessCountDesc" | i18n }}
          </div>
          <div id="maxAccessCountHelp" class="box-footer" *ngIf="editMode">
            <p>{{ "maxAccessCountDesc" | i18n }}</p>
            {{ "currentAccessCount" | i18n }}: <strong>{{ send.accessCount }}</strong>
          </div>
        </div>
        <div class="box">
          <div class="box-content">
            <div class="box-content-row box-content-row-flex" appBoxRow>
              <div class="row-main">
                <label for="password">{{
                  (hasPassword ? "newPassword" : "password") | i18n
                }}</label>
                <input
                  id="password"
                  name="password"
                  aria-describedby="passwordHelp"
                  type="{{ showPassword ? 'text' : 'password' }}"
                  formControlName="password"
                  appInputVerbatim
                />
              </div>
              <div class="action-buttons">
                <button
                  type="button"
                  class="row-btn"
                  appStopClick
                  appA11yTitle="{{ 'toggleVisibility' | i18n }}"
                  [attr.aria-pressed]="showPassword"
                  (click)="togglePasswordVisible()"
                >
                  <i
                    class="bwi bwi-lg"
                    aria-hidden="true"
                    [ngClass]="{ 'bwi-eye': !showPassword, 'bwi-eye-slash': showPassword }"
                  ></i>
                </button>
              </div>
            </div>
          </div>
          <div id="passwordHelp" class="box-footer">
            {{ "sendPasswordDesc" | i18n }}
          </div>
        </div>
        <div class="box">
          <h2 class="box-header">
            <label for="notes">{{ "notes" | i18n }}</label>
          </h2>
          <div class="box-content">
            <div class="box-content-row" appBoxRow>
              <textarea
                id="notes"
                name="notes"
                aria-describedby="notesHelp"
                formControlName="notes"
                rows="6"
              ></textarea>
            </div>
          </div>
          <div id="notesHelp" class="box-footer">
            {{ "sendNotesDesc" | i18n }}
          </div>
        </div>
        <div class="box">
          <div class="box-content">
            <div class="box-content-row box-content-row-checkbox" appBoxRow>
              <label for="hideEmail">{{ "hideEmail" | i18n }}</label>
              <input id="hideEmail" type="checkbox" name="HideEmail" formControlName="hideEmail" />
            </div>
          </div>
        </div>
        <div class="box">
          <div class="box-content">
            <div class="box-content-row box-content-row-checkbox" appBoxRow>
              <label for="disabled">{{ "disableSend" | i18n }}</label>
              <input id="disabled" type="checkbox" name="disabled" formControlName="disabled" />
            </div>
          </div>
        </div>
      </div>
      <div class="box">
        <h2 class="box-header">
          {{ "share" | i18n }}
        </h2>
        <div class="box-content">
          <div class="box-content-row" appBoxRow *ngIf="editMode">
            <label for="link">{{ "sendLinkLabel" | i18n }}</label>
            <input id="link" name="link" formControlName="link" readonly />
          </div>
          <div class="box-content-row box-content-row-checkbox" appBoxRow>
            <label for="copyLink">{{ "copySendLinkOnSave" | i18n }}</label>
            <input id="copyLink" name="copyLink" formControlName="copyLink" type="checkbox" />
          </div>
        </div>
      </div>
    </div>
  </div>
  <div class="footer">
    <button
      type="submit"
      class="primary btn-submit"
      appA11yTitle="{{ 'save' | i18n }}"
      *ngIf="!disableSend"
    >
      <i class="bwi bwi-spinner bwi-spin" title="{{ 'loading' | i18n }}" aria-hidden="true"></i>
      <span><i class="bwi bwi-save-changes bwi-lg bwi-fw" aria-hidden="true"></i></span>
    </button>
    <button type="button" (click)="cancel()">
      {{ "cancel" | i18n }}
    </button>
    <div class="right">
      <button
        type="button"
        (click)="copyLinkToClipboard(link)"
        appA11yTitle="{{ 'copySendLinkToClipboard' | i18n }}"
        *ngIf="editMode"
      >
        <i class="bwi bwi-clone bwi-lg bwi-fw" aria-hidden="true"></i>
      </button>
      <button
        #deleteBtn
        type="button"
        (click)="delete()"
        class="danger"
        appA11yTitle="{{ 'delete' | i18n }}"
        *ngIf="editMode"
      >
        <i
          class="bwi bwi-trash bwi-lg bwi-fw"
          [hidden]="$any(deleteBtn).loading"
          aria-hidden="true"
        ></i>
        <i
          class="bwi bwi-spinner bwi-spin bwi-lg bwi-fw"
          [hidden]="!$any(deleteBtn).loading"
          aria-hidden="true"
        ></i>
      </button>
    </div>
  </div>
</form>
